//
//  FriendLikeGitfAddController.m
//  CheekiOS
//
//  Created by mac on 2017/7/25.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "FriendLikeGitfAddController.h"
#import "HQConversationViewController.h"
@interface FriendLikeGitfAddController ()

/**
 礼物图片
 */
@property (nonatomic, strong) UIImageView *imageView;
/**
 拒绝添加
 */
@property (nonatomic, strong) UIButton *RefusedButton;
/**
 确认添加
 */
@property (nonatomic, strong) UIButton *ConfirmButton;

/**
 提示
 */
@property (nonatomic, strong) UILabel *label;

/**
 拒绝提示
 */
@property (nonatomic, strong) UILabel *RefusedLab;

/**
 返回
 */
@property (nonatomic, strong) UIButton *backButton;

/**
 去聊天
 */
@property (nonatomic, strong) UIButton *GomessageButton;





@end

@implementation FriendLikeGitfAddController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"礼物";
    [self setNavgationBarHiddenNo];
    [self selfTitleFontColor];
    
    
    _imageView = [[UIImageView alloc] init];
//    _imageView.contentMode = UIViewContentModeScaleAspectFit;//居中 有空白
//    _imageView.contentMode = UIViewContentModeScaleToFill;//拉长
//    _imageView.contentMode = UIViewContentModeScaleAspectFill;//拉宽
    _imageView.frame = CGRectMake(0, 0, KScreenWidth, KScreenWidth);
    //此处拼接  后台说.1拼接，就是被送礼大图地址
    [_imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@.1",HttpImgUrl(_model.img) ]]placeholderImage:[UIImage imageNamed:@"llustration"]];
    [self.view addSubview:_imageView];
    
    _label = [[UILabel alloc] initWithFrame:CGRectMake(0, _imageView.bottom+10, KScreenWidth, 25)];
    _label.font = FontP(15);
    _label.textColor = ColorI(0x2e353f);
    _label.textAlignment = NSTextAlignmentCenter;
    _label.text = @"加对方好友后，可获得礼物哦！";
    [self.view addSubview:_label];
    
    _RefusedButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:_RefusedButton];
    _RefusedButton.backgroundColor = [UIColor blackColor];
    [_RefusedButton setTitleColor:Theme_Color_White forState:UIControlStateNormal];
    _RefusedButton.titleLabel.font = FontP(15);
    [_RefusedButton setTitle:@"拒绝添加" forState:UIControlStateNormal];
    _RefusedButton.layer.cornerRadius = 15*SCREEN_WIDTH_RATIO47;
    _RefusedButton.layer.masksToBounds = YES;
    [_RefusedButton addTarget:self action:@selector(RefusedButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_RefusedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_label.mas_bottom).offset(25*SCREEN_WIDTH_RATIO47);
        make.left.equalTo(self.view).offset(50*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(40*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo((KScreenWidth-155*SCREEN_WIDTH_RATIO47)/2);
    }];

    
    
    _ConfirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:_ConfirmButton];
    _ConfirmButton.backgroundColor = Colorbackground;
    [_ConfirmButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _ConfirmButton.titleLabel.font = FontP(15);
    [_ConfirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_label.mas_bottom).offset(25*SCREEN_WIDTH_RATIO47);
        make.left.equalTo(_RefusedButton.mas_right).offset(55*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo((KScreenWidth-155*SCREEN_WIDTH_RATIO47)/2);
        make.height.mas_equalTo(40*SCREEN_WIDTH_RATIO47);
    }];
    [_ConfirmButton setTitle:@"添加好友" forState:UIControlStateNormal];
    _ConfirmButton.layer.cornerRadius = 15*SCREEN_WIDTH_RATIO47;
    _ConfirmButton.layer.masksToBounds = YES;
    [_ConfirmButton addTarget:self action:@selector(ConfirmButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    _RefusedLab = [[UILabel alloc] initWithFrame:CGRectMake(0, _imageView.bottom+35, KScreenWidth, 25)];
    _RefusedLab.font = FontP(15);
    _RefusedLab.textColor = ColorI(0x2e353f);
    _RefusedLab.textAlignment = NSTextAlignmentCenter;
    _RefusedLab.text = @"拒绝对方添加好友请求，礼物已退回";
    _RefusedLab.hidden = YES;
    [self.view addSubview:_RefusedLab];
    
    /********************/

    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:_backButton];
    _backButton.backgroundColor = [UIColor blackColor];
    [_backButton setTitleColor:Theme_Color_White forState:UIControlStateNormal];
    _backButton.titleLabel.font = FontP(10);
    [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_label.mas_bottom).offset(25*SCREEN_WIDTH_RATIO47);
        make.left.equalTo(self.view).offset(50*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(40*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo((KScreenWidth-155*SCREEN_WIDTH_RATIO47)/2);


    }];
    _backButton.layer.cornerRadius = 15*SCREEN_WIDTH_RATIO47;
    _backButton.layer.masksToBounds = YES;
    [_backButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    _backButton.hidden = YES;
    [_backButton setTitle:@"返回" forState:UIControlStateNormal];

    
    
    _GomessageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:_GomessageButton];
    _GomessageButton.backgroundColor = Colorbackground;
    [_GomessageButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _GomessageButton.titleLabel.font = FontP(10);
    [_GomessageButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_label.mas_bottom).offset(25*SCREEN_WIDTH_RATIO47);
        make.left.equalTo(_backButton.mas_right).offset(55*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo((KScreenWidth-155*SCREEN_WIDTH_RATIO47)/2);
        make.height.mas_equalTo(40*SCREEN_WIDTH_RATIO47);
    }];
    _GomessageButton.layer.cornerRadius = 15;
    _GomessageButton.layer.masksToBounds = YES;
    [_GomessageButton addTarget:self action:@selector(GomessageButtonClick) forControlEvents:UIControlEventTouchUpInside];
    _GomessageButton.hidden = YES;
    [_backButton setTitle:@"去聊天" forState:UIControlStateNormal];

}

- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:YES];

}

- (void)GomessageButtonClick{
WEAKSELF
    HQConversationViewController *conversationVC = [[HQConversationViewController alloc]init];
    conversationVC.conversationType = ConversationType_PRIVATE;
    conversationVC.targetId = @(_model.wid).stringValue;
    conversationVC.title = _model.nickName;
    [conversationVC sendMessage:[RCTextMessage messageWithContent:@"我们已经是好友了，可以尽情聊天了"] pushContent:@"friend"];
    conversationVC.hidesBottomBarWhenPushed = YES;
    [weakSelf.navigationController pushViewController:conversationVC animated:YES];

}

- (void)RefusedButtonClick{
    
    
    [HQHttpManager pickWooWithUid:[HQHttpManager getUserId] wid:@(_model.wid) type:@(1) successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
        
        if (isSuccess) {
            _ConfirmButton.hidden = YES;
            _RefusedButton.hidden = YES;
            _label.hidden = YES;
            _RefusedLab.hidden = NO;
        }else{
        
        }
    }];


}
- (void)ConfirmButtonClick{
    
    NSString *str = [NSString stringWithFormat:@"%ld",(long)_model.userGiftId];
    
    [HQHttpManager receiveGiftWithUserGiftId:str successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {
        if (isSuccess) {
            
        }
    }];
    
    
    [HQHttpManager pickWooWithUid:[HQHttpManager getUserId] wid:@(_model.wid) type:@(2) successBlock:^(BOOL isSuccess, NSDictionary *resultDic) {

        if (isSuccess) {
            _ConfirmButton.hidden = YES;
            _RefusedButton.hidden = YES;
            if (_model.status == 3) {
                _label.text = @"礼物已过期，添加好友成功";
            }else{
                _label.text = @"已添加对方好友，礼物已进入你的账户";
            }
            _backButton.hidden = NO;
            _GomessageButton.hidden = NO;
        }
    }];

}

-(void)setModel:(HRLikeMeModel *)model{
    _model = model;
 
}



@end
